<%@ page import="wtc.stu.dao.StuDaoMajor" %>
<%@ page import="wtc.stu.entity.StuEntity" %>
<%@ page import="java.util.List" %>
<%@ page import="wtc.stu.dao.StuDaoDepartment" %><%--
  Created by IntelliJ IDEA.
  User: 马可
  Date: 2022/10/29
  Time: 16:26
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <link rel="stylesheet" href="css/tableFive.css" type="text/css">
    <link rel="stylesheet" href="css/optionsTwo.css" type="text/css">
    <title>专业信息管理</title>
</head>
<body>
<%--信息一览功能--%>
<div class="table">
    <table>
        <caption>专业信息一览</caption>
        <thead>
        <tr>
            <th>专业编号</th>
            <th>系别编号</th>
            <th>专业名称</th>
            <th>专业备注</th>
            <th>操作选项</th>
        </tr>
        </thead>
        <%--从数据库获取上述字段的数据--%>
        <%
            // 通过对应类的getAll方法从数据库获取数据并存储到列表当中，遍历列表以获取各字段的数据
            StuDaoMajor daoMajor = new StuDaoMajor();
            List<StuEntity> ar = daoMajor.getAll();
            for (StuEntity stuEntity : ar) {
        %>
        <tbody>
        <tr>
            <td><%=stuEntity.getZid() %>
            </td>
            <td><%=stuEntity.getXid() %>
            </td>
            <td><%=stuEntity.getZname()%>
            </td>
            <td><%=stuEntity.getZremark() %>
            </td>
            <%--通过a标签传值到指定的servlet当中，以获取要删除的数据的编号--%>
            <td class="xg"><a href="majorServlet.jsp?delZid=<%=stuEntity.getZid()%>">删除</a></td>
            <%
                }
            %>
            <td style="display: none"></td>
        </tr>
        <tr>
            <td colspan="5" align="center" class="options"><a href="#add">增加专业信息</a></td>
        </tr>
        </tbody>
    </table>
</div>
<%--增加功能--%>
<div class="insert">
    <%--通过form表单将输入的数据传递到指定servlet当中--%>
    <form method="post" action="majorServlet.jsp">
        <span id="add">增加专业信息</span>
        <label>
            <input type="text" name="zid" placeholder="专业编号" class="input_box"
                   oninput="value=value.replace(/\D/g,'')">
        </label>
        <label>
            <%--从数据库获取数据作为选项--%>
            <select class="select" name="xid">
                <option selected hidden disabled>-请选择新增专业所属的系别-</option>
                <%
                    StuDaoDepartment daoDepartmentAdd = new StuDaoDepartment();
                    List<StuEntity> arDepartmentAdd = daoDepartmentAdd.getAll();
                    for (StuEntity stuEntity : arDepartmentAdd) {
                %>
                <option value="<%=stuEntity.getXid()%>"><%=stuEntity.getXname()%>
                </option>
                <%
                    }
                %>
            </select>
        </label>
        <label>
            <input type="text" name="zname" placeholder="专业名称" class="input_box">
        </label>
        <label>
            <input type="text" name="zremark" placeholder="专业备注" class="input_box">
        </label>
        <label>
            <input type="submit" value="提交" class="button_box">
        </label>
    </form>
</div>
<%--修改功能--%>
<div class="update">
    <%--通过form表单将输入的数据传递到指定servlet当中--%>
    <form method="post" action="majorServlet.jsp">
        <span id="ud">修改专业信息</span>
        <label>
            <%--从数据库获取数据作为要修改的选项--%>
            <select class="select" name="newZid">
                <option selected hidden disabled>-请你要修改的专业编号-</option>
                <%
                    StuDaoMajor daoMajorUpdate = new StuDaoMajor();
                    List<StuEntity> arUpdate = daoMajorUpdate.getAll();
                    for (StuEntity stuEntity : arUpdate) {
                %>
                <option value="<%=stuEntity.getZid()%>"><%=stuEntity.getZid()%>
                </option>
                <%
                    }
                %>
            </select>
        </label>
        <label>
            <%--从数据库获取数据作为要修改的选项--%>
            <select class="select" name="newXid">
                <option selected hidden disabled>-请选择专业修改后所属的系别-</option>
                <%
                    StuDaoDepartment daoDepartmentUpdate = new StuDaoDepartment();
                    List<StuEntity> arDepartmentUpdate = daoDepartmentUpdate.getAll();
                    for (StuEntity stuEntity : arDepartmentUpdate) {
                %>
                <option value="<%=stuEntity.getXid()%>"><%=stuEntity.getXname()%>
                </option>
                <%
                    }
                %>
            </select>
        </label>
        <label>
            <input type="text" name="newZname" placeholder="修改后的专业名称" class="input_box">
        </label>
        <label>
            <input type="text" name="newZremark" placeholder="修改后的专业备注" class="input_box">
        </label>
        <label>
            <input type="submit" value="提交" class="button_box">
        </label>
    </form>
</div>
</body>
</html>
